

layui.use(['layer', 'form'], function(){
    var layer = layui.layer,
        form = layui.form;

    var mainContainer = document.getElementById('myChart');
    var myChart = echarts.init(mainContainer);

    var option = {
        color: ['#3569e8'],
        tooltip : {
            trigger: 'axis',
            show:false,
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis : [
            {
                type : 'category',
                data : [],
                axisTick: {
                    alignWithLabel: true
                }
            }
        ],
        yAxis : [
            {
                type : 'value',
                axisLine:{
                    show:false,
                }
            }

        ],
        series : [
            {
                name:'数量',
                type:'bar',
                barWidth: '60%',
                data:[],
                itemStyle: {
                    normal: {
                        label: {
                            show: true, //开启显示
                            position: 'top', //在上方显示
                            textStyle: { //数值样式
                                color: '#96A9B5',
                                fontSize: 16
                            }
                        }
                    }
                }
            }
        ]
    };
    myChart.setOption(option);


        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r !== null) return decodeURI(r[2]);
            return null;
        }

        var param = getQueryString('phone');

        $.ajax(
            {
                url: '/api/getTableInfo',
                data: {phone: param},
                type: 'GET',
                dataType: 'json',
                success: function (data) {

                        myChart.setOption({
                            xAxis: {data: data.listDate},
                            series: [
                                {name: '数量', data: data.listNumber}
                            ]
                        });

                },
                error: function (error) {
                    //请求失败  获取的报错信息
                    console.log(error);
                }
            }
        );


    $.ajax(
        {
            url: '/api/getAverage',
            data: {phone: param},
            type: 'GET',
            dataType: 'json',
            success: function (data) {
                $("#mx").html(data.max);
                $("#min").html(data.min);
                $("#avg").html(data.average);
                $("#tir").html(data.degree);
                $("#time").html(data.Date);
                $("#mg").attr("src",data.img);
            },
            error: function (error) {
                //请求失败  获取的报错信息
                console.log(error);
            }
        }
    );

});
